package com.study.seckill.web.page;

import com.study.exceptions.CourseException;
import com.study.exceptions.CourseSeckillException;
import com.study.exceptions.CourseSeckillOrderException;
import com.study.exceptions.UserException;
import com.study.util.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;

/**
 * @ClassName: ExceptionHandler
 * @Author: wYin
 * @Date: 2022/3/17 15:49
 */
@ControllerAdvice
@Slf4j
public class ExceptionHandler {
    @org.springframework.web.bind.annotation.ExceptionHandler(UserException.class)
    public String userExceptionHandler(UserException e, Model model){
        log.error(e.getMessage());
//        return new ResponseResult<>(500,"ex",e.getMessage());
        model.addAttribute("msg",e.getMessage());
        return "error_show";
    }
    @org.springframework.web.bind.annotation.ExceptionHandler(CourseException.class)
    public String courseExceptionHandler(CourseException e,Model model){
        log.error(e.getMessage());
//        return new ResponseResult<>(500,"ex",e.getMessage());
        model.addAttribute("msg",e.getMessage());
        return "error_show";
    }
    @org.springframework.web.bind.annotation.ExceptionHandler(CourseSeckillException.class)
    public String courseSeckillExceptionHandler(CourseSeckillException e,Model model){
        log.error(e.getMessage());
//        return new ResponseResult<>(500,"ex",e.getMessage());
        model.addAttribute("msg",e.getMessage());
        return "error_show";
    }
    @org.springframework.web.bind.annotation.ExceptionHandler(CourseSeckillOrderException.class)
    public String courseSeckillOrderExceptionHandler(CourseSeckillOrderException e,Model model){
        log.error(e.getMessage());
//        return new ResponseResult<>(500,"ex",e.getMessage());
        model.addAttribute("msg",e.getMessage());
        return "error_show";
    }
    @org.springframework.web.bind.annotation.ExceptionHandler(Exception.class)
    public String exceptionHandler(Exception e,Model model){
        log.error(e.getMessage());
//        return new ResponseResult<>(500,"ex",e.getCause().toString());
        model.addAttribute("msg",e.getMessage());
        return "error_show";
    }
}
